const bluemp      = require('bluemp');

const BaseService = require('./base-service').BaseService;

const {Configuration} = require('../constants');

class BlueMPService extends BaseService {

    get bluempConfig() {
        return this.getApplicationConfiguration(Configuration.BLUEMP);
    }

    get bluempClient() {
        if (!this._bluempClient) {
            let blueConfig = this.bluempConfig;
            this._bluempClient = bluemp.createMPClient(blueConfig.client_id, blueConfig.client_secret);
        }

        return this._bluempClient;
    }
    
    getAuthorizeURL(redirectURI) {
        return this.bluempClient.getAuthorizeURL(redirectURI);
    }

    getAccessToken(type, params, parentCallback) {
        return this.bluempClient.getAccessToken(type, params, (result) => {
            parentCallback(result);
        });
    }

    getEnterpriseInfo(accessToken, parentCallback) {
        return this.bluempClient.getEnterpriseInfo(accessToken, (result) => {
            parentCallback(result);
        });
    }
}

exports.BlueMPService = BlueMPService;